package cn.e4j.modular.crm.controller.base;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.crm.entity.GwatT;
import cn.e4j.modular.crm.entity.GwatlT;
import cn.e4j.modular.crm.service.GwatTService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 配件仓库库位设置 控制层
 * @author mengyb
 * @date 2019-04-10
 */
@Controller
@RequestMapping("/base/gwai601")
public class Gwai601Controller extends BaseController {

    @Autowired
    private GwatTService gwatTService;

    /**
     * 跳转至配件仓库库位设置主界面
     *
     * @return
     */
    @RequiresPermissions("base:gwai601:init")
    @RequestMapping(value = {"", "/init"})
    public String index() {
        return "/pc/crm/base/gwai601.html";
    }

    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/getList")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = gwatTService.getList(inDto, page);

        return new PageReData(page, list);

    }

    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/getGwasPageList")
    @ResponseBody
    public ResponseData getGwasPageList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();

        List<Map<String, Object>> list = gwatTService.getGwasPageList(inDto, page);

        return new PageReData(page, list);

    }

    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/getGwasList")
    @ResponseBody
    public Dto getGwasList(@DtoParam DtoWapper dtoWapper) {

        Dto inDto = dtoWapper.getDto();

        List<Map<String, Object>> list = gwatTService.getGwasList(inDto);

        Dto outDto= Dtos.newDto();

        outDto.put("list", list);

        return outDto;

    }


    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/add")
    @ResponseBody
    public ResponseData add(GwatT gwatT, GwatlT gwatlT) {
        if (gwatTService.existedTheParams(gwatT)) {
            return new ErrorResponseData(BizExceptionEnum.EXISTED_THE_PARAMS.getCode(),
                    BizExceptionEnum.EXISTED_THE_PARAMS.getMessage());
        } else {
            gwatTService.add(gwatT, gwatlT);
            return SUCCESS_TIP;
        }
    }

    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/edit")
    @ResponseBody
    public ResponseData edit(GwatT gwatT, GwatlT gwatlT) {
        gwatTService.edit(gwatT, gwatlT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/delRow")
    @ResponseBody
    public ResponseData delRow(GwatT gwatT, GwatlT gwatlT) {
        gwatTService.delRow(gwatT, gwatlT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai601:init")
    @RequestMapping("/delRows")
    @ResponseBody
    public ResponseData delRows(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwatT> gwatTList = inDto.getReqList(GwatT.class);
        gwatTService.delRows(gwatTList);
        return SUCCESS_TIP;
    }


}
